package com.xoms.pad.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import com.alibaba.fastjson.JSON;
import com.mysql.fabric.xmlrpc.base.Array;
import com.xoms.pad.controller.res.ListResult;
import com.xoms.pad.controller.res.bean.RRoomBean;
import com.xoms.pad.controller.springmvc.req.GetRoomParam;
import com.xoms.pad.model.AccountBean;
import com.xoms.pad.service.exception.ServiceException;
import com.xoms.pad.service.impl.RoomServiceImpl;

/**
 * 影厅信息
 * 
 * @author stallmandu
 *
 */
@Component
public class RoomController {
	
	@Autowired
	RoomServiceImpl roomServiceImpl;
	
	/**
	 * 获取维度
	 * 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RRoomBean> getRoom(@Validated GetRoomParam param, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RRoomBean> result = new ListResult<>();
		
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
//			int page = NumUtil.toInt(param.getPage(), 0);
//			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			
			String rid = param.getRid();
			String name = param.getName();
			String dids = param.getDids();
			
			
			List<String> lists = new ArrayList<>();
			if( dids != null && !dids.equals("")){
				String[] didArr= dids.split(",");
				for( int i = 0 ; i<didArr.length;i++){
					String did = didArr[i];
					if( did != null && !did.equals("")){
						lists.add(did);
					}
				}
				
			}
			 
			List<RRoomBean> resData = roomServiceImpl.getRoom(rid,name,lists);
			
			
			if (resData != null) {
				result.setData(resData);
				result.setTotalSize(resData.size());
			}
			
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
}
